Imports cmplib01
Imports System.Drawing.Drawing2D

Public Class ctlSelectedChitProperties
    Inherits System.Windows.Forms.UserControl

    Public Event ShowRuleRange(ByVal ruleio As Rule)
    Public Event ResourceSelected(ByVal res As ResourcePoolItem)
    Public Event ShowRuleDetails(ByVal ruleio As Rule)
    Public Event ShowResourceDetails(ByVal res As ResourcePoolItem)
    Public Event RedrawRequest()


#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'UserControl overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents pnlSecondary As System.Windows.Forms.Panel
    Friend WithEvents lblSelectedChit As System.Windows.Forms.Label
    Friend WithEvents pnlProperties As System.Windows.Forms.Panel
    Friend WithEvents imlSecondaryTreeIcons As System.Windows.Forms.ImageList
    Friend WithEvents txtSelectedChitName As System.Windows.Forms.TextBox
    Friend WithEvents lblOrders As System.Windows.Forms.Label
    Friend WithEvents cboOrders As System.Windows.Forms.ComboBox
    Friend WithEvents lblChitDetails As System.Windows.Forms.Label
    Friend WithEvents tvwSecondary As System.Windows.Forms.TreeView
    Friend WithEvents splThisIsANiceSplitter As System.Windows.Forms.Splitter
    Friend WithEvents tvwProperties As System.Windows.Forms.TreeView
    Friend WithEvents imlPropertyIcons As System.Windows.Forms.ImageList
    Friend WithEvents pnlStatistics As System.Windows.Forms.Panel
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents pnlStats As System.Windows.Forms.Panel
    Friend WithEvents pnlDetails As System.Windows.Forms.Panel
    Friend WithEvents picMaxPointValue As System.Windows.Forms.PictureBox
    Friend WithEvents picCurrentPVPercent As System.Windows.Forms.PictureBox
    Friend WithEvents picSpeed As System.Windows.Forms.PictureBox
    Friend WithEvents picZOC As System.Windows.Forms.PictureBox
    Friend WithEvents mnuWaypointPopup As System.Windows.Forms.ContextMenuStrip
    Friend WithEvents mnuOrders As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents mnuSpeed As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents mnuRemoveWaypoint As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents mnuEngage As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents mnuHold As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents mnuWithdraw As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents mnuDigin As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents mnu100speed As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents mnu75speed As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents mnu50speed As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents mnu25speed As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents mnuEnterspeed As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents ToolStripMenuItem1 As System.Windows.Forms.ToolStripSeparator
    Friend WithEvents mnuRemoveAllWaypoints As System.Windows.Forms.ToolStripMenuItem
    Friend WithEvents picSize As System.Windows.Forms.PictureBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(ctlSelectedChitProperties))
        Me.pnlSecondary = New System.Windows.Forms.Panel
        Me.lblSelectedChit = New System.Windows.Forms.Label
        Me.pnlProperties = New System.Windows.Forms.Panel
        Me.pnlDetails = New System.Windows.Forms.Panel
        Me.lblChitDetails = New System.Windows.Forms.Label
        Me.tvwProperties = New System.Windows.Forms.TreeView
        Me.imlPropertyIcons = New System.Windows.Forms.ImageList(Me.components)
        Me.pnlStats = New System.Windows.Forms.Panel
        Me.Label1 = New System.Windows.Forms.Label
        Me.pnlStatistics = New System.Windows.Forms.Panel
        Me.picCurrentPVPercent = New System.Windows.Forms.PictureBox
        Me.picMaxPointValue = New System.Windows.Forms.PictureBox
        Me.picSpeed = New System.Windows.Forms.PictureBox
        Me.picZOC = New System.Windows.Forms.PictureBox
        Me.picSize = New System.Windows.Forms.PictureBox
        Me.splThisIsANiceSplitter = New System.Windows.Forms.Splitter
        Me.tvwSecondary = New System.Windows.Forms.TreeView
        Me.imlSecondaryTreeIcons = New System.Windows.Forms.ImageList(Me.components)
        Me.cboOrders = New System.Windows.Forms.ComboBox
        Me.lblOrders = New System.Windows.Forms.Label
        Me.txtSelectedChitName = New System.Windows.Forms.TextBox
        Me.mnuWaypointPopup = New System.Windows.Forms.ContextMenuStrip(Me.components)
        Me.mnuOrders = New System.Windows.Forms.ToolStripMenuItem
        Me.mnuEngage = New System.Windows.Forms.ToolStripMenuItem
        Me.mnuHold = New System.Windows.Forms.ToolStripMenuItem
        Me.mnuWithdraw = New System.Windows.Forms.ToolStripMenuItem
        Me.mnuDigin = New System.Windows.Forms.ToolStripMenuItem
        Me.mnuSpeed = New System.Windows.Forms.ToolStripMenuItem
        Me.mnu100speed = New System.Windows.Forms.ToolStripMenuItem
        Me.mnu75speed = New System.Windows.Forms.ToolStripMenuItem
        Me.mnu50speed = New System.Windows.Forms.ToolStripMenuItem
        Me.mnu25speed = New System.Windows.Forms.ToolStripMenuItem
        Me.mnuEnterspeed = New System.Windows.Forms.ToolStripMenuItem
        Me.ToolStripMenuItem1 = New System.Windows.Forms.ToolStripSeparator
        Me.mnuRemoveWaypoint = New System.Windows.Forms.ToolStripMenuItem
        Me.mnuRemoveAllWaypoints = New System.Windows.Forms.ToolStripMenuItem
        Me.pnlSecondary.SuspendLayout()
        Me.pnlProperties.SuspendLayout()
        Me.pnlDetails.SuspendLayout()
        Me.pnlStats.SuspendLayout()
        Me.pnlStatistics.SuspendLayout()
        CType(Me.picCurrentPVPercent, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.picMaxPointValue, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.picSpeed, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.picZOC, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.picSize, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.mnuWaypointPopup.SuspendLayout()
        Me.SuspendLayout()
        '
        'pnlSecondary
        '
        Me.pnlSecondary.BackColor = System.Drawing.Color.SteelBlue
        Me.pnlSecondary.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlSecondary.Controls.Add(Me.lblSelectedChit)
        Me.pnlSecondary.Dock = System.Windows.Forms.DockStyle.Top
        Me.pnlSecondary.Location = New System.Drawing.Point(0, 0)
        Me.pnlSecondary.Name = "pnlSecondary"
        Me.pnlSecondary.Size = New System.Drawing.Size(208, 48)
        Me.pnlSecondary.TabIndex = 10
        '
        'lblSelectedChit
        '
        Me.lblSelectedChit.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblSelectedChit.Location = New System.Drawing.Point(8, 9)
        Me.lblSelectedChit.Name = "lblSelectedChit"
        Me.lblSelectedChit.Size = New System.Drawing.Size(152, 24)
        Me.lblSelectedChit.TabIndex = 1
        Me.lblSelectedChit.Text = "Selected Chit"
        '
        'pnlProperties
        '
        Me.pnlProperties.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlProperties.Controls.Add(Me.pnlDetails)
        Me.pnlProperties.Controls.Add(Me.pnlStats)
        Me.pnlProperties.Controls.Add(Me.splThisIsANiceSplitter)
        Me.pnlProperties.Controls.Add(Me.tvwSecondary)
        Me.pnlProperties.Controls.Add(Me.cboOrders)
        Me.pnlProperties.Controls.Add(Me.lblOrders)
        Me.pnlProperties.Controls.Add(Me.txtSelectedChitName)
        Me.pnlProperties.Controls.Add(Me.pnlSecondary)
        Me.pnlProperties.Dock = System.Windows.Forms.DockStyle.Fill
        Me.pnlProperties.Location = New System.Drawing.Point(0, 0)
        Me.pnlProperties.Name = "pnlProperties"
        Me.pnlProperties.Size = New System.Drawing.Size(210, 360)
        Me.pnlProperties.TabIndex = 14
        '
        'pnlDetails
        '
        Me.pnlDetails.Controls.Add(Me.lblChitDetails)
        Me.pnlDetails.Controls.Add(Me.tvwProperties)
        Me.pnlDetails.Dock = System.Windows.Forms.DockStyle.Fill
        Me.pnlDetails.Location = New System.Drawing.Point(0, 213)
        Me.pnlDetails.Name = "pnlDetails"
        Me.pnlDetails.Size = New System.Drawing.Size(208, 65)
        Me.pnlDetails.TabIndex = 45
        '
        'lblChitDetails
        '
        Me.lblChitDetails.BackColor = System.Drawing.Color.DarkSeaGreen
        Me.lblChitDetails.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.lblChitDetails.Dock = System.Windows.Forms.DockStyle.Top
        Me.lblChitDetails.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(204, Byte))
        Me.lblChitDetails.ForeColor = System.Drawing.Color.Black
        Me.lblChitDetails.Location = New System.Drawing.Point(0, 0)
        Me.lblChitDetails.Name = "lblChitDetails"
        Me.lblChitDetails.Size = New System.Drawing.Size(208, 17)
        Me.lblChitDetails.TabIndex = 23
        Me.lblChitDetails.Text = "Details"
        '
        'tvwProperties
        '
        Me.tvwProperties.BorderStyle = System.Windows.Forms.BorderStyle.None
        Me.tvwProperties.Dock = System.Windows.Forms.DockStyle.Fill
        Me.tvwProperties.ImageIndex = 0
        Me.tvwProperties.ImageList = Me.imlPropertyIcons
        Me.tvwProperties.Location = New System.Drawing.Point(0, 0)
        Me.tvwProperties.Name = "tvwProperties"
        Me.tvwProperties.SelectedImageIndex = 0
        Me.tvwProperties.Size = New System.Drawing.Size(208, 65)
        Me.tvwProperties.TabIndex = 27
        '
        'imlPropertyIcons
        '
        Me.imlPropertyIcons.ImageStream = CType(resources.GetObject("imlPropertyIcons.ImageStream"), System.Windows.Forms.ImageListStreamer)
        Me.imlPropertyIcons.TransparentColor = System.Drawing.Color.Transparent
        Me.imlPropertyIcons.Images.SetKeyName(0, "")
        Me.imlPropertyIcons.Images.SetKeyName(1, "")
        Me.imlPropertyIcons.Images.SetKeyName(2, "")
        Me.imlPropertyIcons.Images.SetKeyName(3, "")
        Me.imlPropertyIcons.Images.SetKeyName(4, "")
        Me.imlPropertyIcons.Images.SetKeyName(5, "")
        Me.imlPropertyIcons.Images.SetKeyName(6, "")
        Me.imlPropertyIcons.Images.SetKeyName(7, "")
        Me.imlPropertyIcons.Images.SetKeyName(8, "")
        Me.imlPropertyIcons.Images.SetKeyName(9, "")
        Me.imlPropertyIcons.Images.SetKeyName(10, "")
        Me.imlPropertyIcons.Images.SetKeyName(11, "")
        Me.imlPropertyIcons.Images.SetKeyName(12, "battlegroupicon.bmp")
        Me.imlPropertyIcons.Images.SetKeyName(13, "uniticon.bmp")
        Me.imlPropertyIcons.Images.SetKeyName(14, "reinforcementrangeicon.bmp")
        Me.imlPropertyIcons.Images.SetKeyName(15, "lilSkull.bmp")
        Me.imlPropertyIcons.Images.SetKeyName(16, "waypointIcon.bmp")
        Me.imlPropertyIcons.Images.SetKeyName(17, "fedit.bmp")
        '
        'pnlStats
        '
        Me.pnlStats.Controls.Add(Me.Label1)
        Me.pnlStats.Controls.Add(Me.pnlStatistics)
        Me.pnlStats.Dock = System.Windows.Forms.DockStyle.Top
        Me.pnlStats.Location = New System.Drawing.Point(0, 101)
        Me.pnlStats.Name = "pnlStats"
        Me.pnlStats.Size = New System.Drawing.Size(208, 112)
        Me.pnlStats.TabIndex = 44
        '
        'Label1
        '
        Me.Label1.BackColor = System.Drawing.Color.DarkSeaGreen
        Me.Label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.Label1.Dock = System.Windows.Forms.DockStyle.Top
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(204, Byte))
        Me.Label1.ForeColor = System.Drawing.Color.Black
        Me.Label1.Location = New System.Drawing.Point(0, 0)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(208, 17)
        Me.Label1.TabIndex = 24
        Me.Label1.Text = "Statistics"
        '
        'pnlStatistics
        '
        Me.pnlStatistics.BackColor = System.Drawing.Color.PowderBlue
        Me.pnlStatistics.Controls.Add(Me.picCurrentPVPercent)
        Me.pnlStatistics.Controls.Add(Me.picMaxPointValue)
        Me.pnlStatistics.Controls.Add(Me.picSpeed)
        Me.pnlStatistics.Controls.Add(Me.picZOC)
        Me.pnlStatistics.Controls.Add(Me.picSize)
        Me.pnlStatistics.Location = New System.Drawing.Point(-1, 16)
        Me.pnlStatistics.Name = "pnlStatistics"
        Me.pnlStatistics.Size = New System.Drawing.Size(210, 104)
        Me.pnlStatistics.TabIndex = 43
        '
        'picCurrentPVPercent
        '
        Me.picCurrentPVPercent.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.picCurrentPVPercent.BackColor = System.Drawing.Color.Gray
        Me.picCurrentPVPercent.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.picCurrentPVPercent.Location = New System.Drawing.Point(8, 74)
        Me.picCurrentPVPercent.Name = "picCurrentPVPercent"
        Me.picCurrentPVPercent.Size = New System.Drawing.Size(196, 18)
        Me.picCurrentPVPercent.TabIndex = 4
        Me.picCurrentPVPercent.TabStop = False
        '
        'picMaxPointValue
        '
        Me.picMaxPointValue.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.picMaxPointValue.BackColor = System.Drawing.Color.Gray
        Me.picMaxPointValue.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.picMaxPointValue.Location = New System.Drawing.Point(8, 57)
        Me.picMaxPointValue.Name = "picMaxPointValue"
        Me.picMaxPointValue.Size = New System.Drawing.Size(196, 18)
        Me.picMaxPointValue.TabIndex = 3
        Me.picMaxPointValue.TabStop = False
        '
        'picSpeed
        '
        Me.picSpeed.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.picSpeed.BackColor = System.Drawing.Color.Gray
        Me.picSpeed.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.picSpeed.Location = New System.Drawing.Point(8, 40)
        Me.picSpeed.Name = "picSpeed"
        Me.picSpeed.Size = New System.Drawing.Size(196, 18)
        Me.picSpeed.TabIndex = 2
        Me.picSpeed.TabStop = False
        '
        'picZOC
        '
        Me.picZOC.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.picZOC.BackColor = System.Drawing.Color.Gray
        Me.picZOC.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.picZOC.Location = New System.Drawing.Point(8, 23)
        Me.picZOC.Name = "picZOC"
        Me.picZOC.Size = New System.Drawing.Size(196, 18)
        Me.picZOC.TabIndex = 1
        Me.picZOC.TabStop = False
        '
        'picSize
        '
        Me.picSize.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        Me.picSize.BackColor = System.Drawing.Color.Gray
        Me.picSize.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.picSize.Location = New System.Drawing.Point(8, 6)
        Me.picSize.Name = "picSize"
        Me.picSize.Size = New System.Drawing.Size(196, 18)
        Me.picSize.TabIndex = 0
        Me.picSize.TabStop = False
        '
        'splThisIsANiceSplitter
        '
        Me.splThisIsANiceSplitter.BackColor = System.Drawing.Color.DarkSeaGreen
        Me.splThisIsANiceSplitter.Dock = System.Windows.Forms.DockStyle.Bottom
        Me.splThisIsANiceSplitter.Location = New System.Drawing.Point(0, 278)
        Me.splThisIsANiceSplitter.Name = "splThisIsANiceSplitter"
        Me.splThisIsANiceSplitter.Size = New System.Drawing.Size(208, 8)
        Me.splThisIsANiceSplitter.TabIndex = 26
        Me.splThisIsANiceSplitter.TabStop = False
        '
        'tvwSecondary
        '
        Me.tvwSecondary.BorderStyle = System.Windows.Forms.BorderStyle.None
        Me.tvwSecondary.Dock = System.Windows.Forms.DockStyle.Bottom
        Me.tvwSecondary.ImageIndex = 0
        Me.tvwSecondary.ImageList = Me.imlSecondaryTreeIcons
        Me.tvwSecondary.Location = New System.Drawing.Point(0, 286)
        Me.tvwSecondary.Name = "tvwSecondary"
        Me.tvwSecondary.SelectedImageIndex = 0
        Me.tvwSecondary.Size = New System.Drawing.Size(208, 72)
        Me.tvwSecondary.TabIndex = 25
        '
        'imlSecondaryTreeIcons
        '
        Me.imlSecondaryTreeIcons.ImageStream = CType(resources.GetObject("imlSecondaryTreeIcons.ImageStream"), System.Windows.Forms.ImageListStreamer)
        Me.imlSecondaryTreeIcons.TransparentColor = System.Drawing.Color.Transparent
        Me.imlSecondaryTreeIcons.Images.SetKeyName(0, "")
        Me.imlSecondaryTreeIcons.Images.SetKeyName(1, "")
        Me.imlSecondaryTreeIcons.Images.SetKeyName(2, "")
        Me.imlSecondaryTreeIcons.Images.SetKeyName(3, "")
        Me.imlSecondaryTreeIcons.Images.SetKeyName(4, "")
        Me.imlSecondaryTreeIcons.Images.SetKeyName(5, "")
        Me.imlSecondaryTreeIcons.Images.SetKeyName(6, "battlegroupicon.bmp")
        Me.imlSecondaryTreeIcons.Images.SetKeyName(7, "uniticon.bmp")
        '
        'cboOrders
        '
        Me.cboOrders.Dock = System.Windows.Forms.DockStyle.Top
        Me.cboOrders.Items.AddRange(New Object() {"Hold", "Withdraw", "Engage", "Dig-In"})
        Me.cboOrders.Location = New System.Drawing.Point(0, 80)
        Me.cboOrders.Name = "cboOrders"
        Me.cboOrders.Size = New System.Drawing.Size(208, 21)
        Me.cboOrders.TabIndex = 21
        Me.cboOrders.Text = "<None>"
        '
        'lblOrders
        '
        Me.lblOrders.BackColor = System.Drawing.Color.DarkSeaGreen
        Me.lblOrders.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.lblOrders.Dock = System.Windows.Forms.DockStyle.Top
        Me.lblOrders.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(204, Byte))
        Me.lblOrders.ForeColor = System.Drawing.Color.Black
        Me.lblOrders.Location = New System.Drawing.Point(0, 63)
        Me.lblOrders.Name = "lblOrders"
        Me.lblOrders.Size = New System.Drawing.Size(208, 17)
        Me.lblOrders.TabIndex = 20
        Me.lblOrders.Text = "Orders"
        '
        'txtSelectedChitName
        '
        Me.txtSelectedChitName.BorderStyle = System.Windows.Forms.BorderStyle.None
        Me.txtSelectedChitName.Dock = System.Windows.Forms.DockStyle.Top
        Me.txtSelectedChitName.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(204, Byte))
        Me.txtSelectedChitName.Location = New System.Drawing.Point(0, 48)
        Me.txtSelectedChitName.Name = "txtSelectedChitName"
        Me.txtSelectedChitName.Size = New System.Drawing.Size(208, 15)
        Me.txtSelectedChitName.TabIndex = 19
        Me.txtSelectedChitName.Text = "<Selected Chit Name>"
        '
        'mnuWaypointPopup
        '
        Me.mnuWaypointPopup.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.mnuOrders, Me.mnuSpeed, Me.ToolStripMenuItem1, Me.mnuRemoveWaypoint, Me.mnuRemoveAllWaypoints})
        Me.mnuWaypointPopup.Name = "mnuWaypointPopup"
        Me.mnuWaypointPopup.Size = New System.Drawing.Size(193, 120)
        '
        'mnuOrders
        '
        Me.mnuOrders.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text
        Me.mnuOrders.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.mnuEngage, Me.mnuHold, Me.mnuWithdraw, Me.mnuDigin})
        Me.mnuOrders.Name = "mnuOrders"
        Me.mnuOrders.Size = New System.Drawing.Size(192, 22)
        Me.mnuOrders.Text = "Orders"
        '
        'mnuEngage
        '
        Me.mnuEngage.Name = "mnuEngage"
        Me.mnuEngage.Size = New System.Drawing.Size(152, 22)
        Me.mnuEngage.Text = "Engage"
        '
        'mnuHold
        '
        Me.mnuHold.Name = "mnuHold"
        Me.mnuHold.Size = New System.Drawing.Size(152, 22)
        Me.mnuHold.Text = "Hold"
        '
        'mnuWithdraw
        '
        Me.mnuWithdraw.Name = "mnuWithdraw"
        Me.mnuWithdraw.Size = New System.Drawing.Size(152, 22)
        Me.mnuWithdraw.Text = "Withdraw"
        '
        'mnuDigin
        '
        Me.mnuDigin.Name = "mnuDigin"
        Me.mnuDigin.Size = New System.Drawing.Size(152, 22)
        Me.mnuDigin.Text = "Dig-in"
        '
        'mnuSpeed
        '
        Me.mnuSpeed.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text
        Me.mnuSpeed.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.mnu100speed, Me.mnu75speed, Me.mnu50speed, Me.mnu25speed, Me.mnuEnterspeed})
        Me.mnuSpeed.Name = "mnuSpeed"
        Me.mnuSpeed.Size = New System.Drawing.Size(192, 22)
        Me.mnuSpeed.Text = "Speed"
        '
        'mnu100speed
        '
        Me.mnu100speed.Name = "mnu100speed"
        Me.mnu100speed.Size = New System.Drawing.Size(152, 22)
        Me.mnu100speed.Text = "100%"
        '
        'mnu75speed
        '
        Me.mnu75speed.Name = "mnu75speed"
        Me.mnu75speed.Size = New System.Drawing.Size(152, 22)
        Me.mnu75speed.Text = "75%"
        '
        'mnu50speed
        '
        Me.mnu50speed.Name = "mnu50speed"
        Me.mnu50speed.Size = New System.Drawing.Size(152, 22)
        Me.mnu50speed.Text = "50%"
        '
        'mnu25speed
        '
        Me.mnu25speed.Name = "mnu25speed"
        Me.mnu25speed.Size = New System.Drawing.Size(152, 22)
        Me.mnu25speed.Text = "25%"
        '
        'mnuEnterspeed
        '
        Me.mnuEnterspeed.Name = "mnuEnterspeed"
        Me.mnuEnterspeed.Size = New System.Drawing.Size(152, 22)
        Me.mnuEnterspeed.Text = "Enter Speed"
        '
        'ToolStripMenuItem1
        '
        Me.ToolStripMenuItem1.Name = "ToolStripMenuItem1"
        Me.ToolStripMenuItem1.Size = New System.Drawing.Size(189, 6)
        '
        'mnuRemoveWaypoint
        '
        Me.mnuRemoveWaypoint.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text
        Me.mnuRemoveWaypoint.Name = "mnuRemoveWaypoint"
        Me.mnuRemoveWaypoint.Size = New System.Drawing.Size(192, 22)
        Me.mnuRemoveWaypoint.Text = "Remove Waypoint"
        '
        'mnuRemoveAllWaypoints
        '
        Me.mnuRemoveAllWaypoints.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text
        Me.mnuRemoveAllWaypoints.Name = "mnuRemoveAllWaypoints"
        Me.mnuRemoveAllWaypoints.Size = New System.Drawing.Size(192, 22)
        Me.mnuRemoveAllWaypoints.Text = "Remove All Waypoints"
        '
        'ctlSelectedChitProperties
        '
        Me.BackColor = System.Drawing.Color.LightSkyBlue
        Me.Controls.Add(Me.pnlProperties)
        Me.Name = "ctlSelectedChitProperties"
        Me.Size = New System.Drawing.Size(210, 360)
        Me.pnlSecondary.ResumeLayout(False)
        Me.pnlProperties.ResumeLayout(False)
        Me.pnlProperties.PerformLayout()
        Me.pnlDetails.ResumeLayout(False)
        Me.pnlStats.ResumeLayout(False)
        Me.pnlStatistics.ResumeLayout(False)
        CType(Me.picCurrentPVPercent, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.picMaxPointValue, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.picSpeed, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.picZOC, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.picSize, System.ComponentModel.ISupportInitialize).EndInit()
        Me.mnuWaypointPopup.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private ptrCurrentGame As CampaignerGameData
    Private ptrSelectedChit As ChitMember

    Private unitReadOnly As Boolean
    'Private selectedUnitType As GroundChitClass_cgd
    Private populatingOrdersList As Boolean
    Private BiggestSize As Single
    Private FastestSpeed As Single
    Private BiggestZOC As Single
    Private HighestMaxPV As Integer

    Private m_PixelsPerOneMile As Single

    Public Property GameData() As CampaignerGameData
        Get
            Return ptrCurrentGame
        End Get
        Set(ByVal Value As CampaignerGameData)
            ptrCurrentGame = Value
        End Set
    End Property

    Public Sub PopulateStatisticBenchmarks()
        '// populates the BiggestLOS, Fastest Speed, biggest ZOC
        '// we can also use PV Max and current PV?
        'Dim gcKey As String
        'Dim gc As GroundChitType

        '// reset!
        BiggestSize = 0
        FastestSpeed = 0
        BiggestZOC = 0
        HighestMaxPV = 0

        Try

            For Each mem As ChitMember In ptrCurrentGame.Chits
                If mem.Size > BiggestSize Then BiggestSize = mem.Size
                If mem.ZOC > BiggestZOC Then BiggestZOC = mem.ZOC

                If mem.UnitType = GroundChitClass_cgd.Battlegroup Then
                    If DirectCast(mem, BattlegroupChit).movementSpeed > FastestSpeed Then FastestSpeed = DirectCast(mem, BattlegroupChit).movementSpeed
                    If DirectCast(mem, BattlegroupChit).deployedpointvalue > HighestMaxPV Then HighestMaxPV = DirectCast(mem, BattlegroupChit).deployedpointvalue
                End If
            Next


        Catch ex As Exception
            HandleException(Me.Name, ex)
        End Try

        If BiggestSize > 1000 Then BiggestSize = 1000

    End Sub

    Public Property PixelsPerOneMile() As Single
        Get
            Return m_PixelsPerOneMile
        End Get
        Set(ByVal Value As Single)
            m_PixelsPerOneMile = Value
        End Set
    End Property

    Public Sub ClearSelectedList(Optional ByVal ChitNameText As String = "<none>")
        ' clears the list of all data 
        txtSelectedChitName.Text = ChitNameText
        tvwProperties.Nodes.Clear()
        tvwSecondary.Nodes.Clear()
        cboOrders.Text = "<none>"

        '// clear each bar
        ClearBar(Me.picSize, "Size")
        ClearBar(Me.picZOC, "Zone Of Control")
        ClearBar(Me.picMaxPointValue, "Maximum PV")
        ClearBar(Me.picCurrentPVPercent, "Current PV")
        ClearBar(Me.picSpeed, "Movement Speed")

    End Sub

    Private Sub drawBar(ByVal strength As Single, ByVal target As PictureBox, ByVal text As String)

        Dim bar As New RectangleF(1, 1, (picSize.Width * strength) - 6, 14)

        Dim imCom As Image = New Bitmap(target.Width, target.Height)
        Dim g As Graphics = Graphics.FromImage(imCom)

        Try
            Dim br As New LinearGradientBrush(bar, Color.Red, Color.Green, LinearGradientMode.Horizontal)

            g.FillRectangle(br, bar)

            g.DrawString(text, Me.Font, New SolidBrush(Color.Yellow), 2, 2)

            target.Image = imCom

        Catch ex As Exception

        End Try
        g.Dispose()

    End Sub

    Private Sub ClearBar(ByVal target As PictureBox, ByVal text As String)
        ' clears the bar to make it gray and puts in subdued text.
        Dim bar As New RectangleF(1, 1, (picSize.Width) - 6, 14)
        Dim imCom As Image = New Bitmap(target.Width, target.Height)
        Dim g As Graphics = Graphics.FromImage(imCom)
        Dim br As New SolidBrush(target.BackColor)

        g.FillRectangle(br, bar)
        g.DrawString(text, Me.Font, New SolidBrush(Color.DarkGray), 2, 2)
        target.Image = imCom
        g.Dispose()

    End Sub

    Public Sub ShowSelectedChitProperties(ByRef selectedChit As ChitMember, ByRef GameData As CampaignerGameData, Optional ByVal ReadonlyUnit As Boolean = True)
        Try
            If selectedChit Is Nothing Then
                ClearSelectedList("<none>")
                Exit Sub
            End If

            ptrCurrentGame = GameData
            ptrSelectedChit = selectedChit

            unitReadOnly = ReadonlyUnit

            ' populate the base properties that all chits share
            PopulateBaseProperties()
            If ptrSelectedChit.UnitType = GroundChitClass_cgd.Objective Then Populate(DirectCast(ptrSelectedChit, InstallationChit))
            If ptrSelectedChit.UnitType = GroundChitClass_cgd.Battlegroup Then Populate(DirectCast(ptrSelectedChit, BattlegroupChit))

        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try
    End Sub

    Private Sub Populate(ByRef inst As InstallationChit)
        ' when viewing an objective, tvwsecondary is used to display rules and resources

        ' clear the secondary view
        tvwSecondary.Nodes.Clear()
        tvwSecondary.ShowRootLines = True

        ' clear the other statistics
        ClearBar(picSpeed, "Movement Speed")
        ClearBar(picMaxPointValue, "Maximum PV")
        ClearBar(picCurrentPVPercent, "PV Percent")

        'Dim key As String
        'Dim rule As Rule
        'Dim ruleT As RuleType

        cboOrders.Enabled = False
        cboOrders.Text = "Hold"   '// not sure why we should even SHOW an orders dropdown for installations.

        If Not inst.chitRules Is Nothing Then
            For Each ru As Rule In inst.chitRules
                Dim ruleNode As New TreeNode
                Dim usesText As String

                ruleNode.Text = ru.ptrRule.RuleName & " [" & ru.usesRemaining & "]"
                ruleNode.Tag = ru
                ruleNode.ImageIndex = 0
                ruleNode.SelectedImageIndex = 0
                If ru.ptrRule.MaxUses = 0 Then
                    usesText = "unlimited"
                Else
                    usesText = ru.usesRemaining
                End If

                Dim availnode, rangenode As New TreeNode
                Dim infoNode As New TreeNode("Click for info")
                infoNode.ForeColor = Color.DarkBlue
                infoNode.ImageIndex = 4
                infoNode.SelectedImageIndex = 4
                infoNode.Tag = "ruleinfo"

                availnode.Text = "Available uses: " & usesText
                availnode.ImageIndex = 2
                availnode.SelectedImageIndex = 2

                rangenode.Text = "Range: " & ru.ptrRule.BasicRange
                rangenode.ImageIndex = 2
                rangenode.SelectedImageIndex = 2

                ruleNode.Nodes.Add(availnode)
                ruleNode.Nodes.Add(rangenode)
                ruleNode.Nodes.Add(infoNode)

                '// if the rule consumes resources:
                If TypeOf ru.ptrRule Is ResourceConsumingRuleType Then
                    Dim resrule As ResourceConsumingRuleType = ru.ptrRule
                    Dim cost As ResourceCost
                    For Each cost In resrule.Costs
                        Dim resusenode As New TreeNode("Uses " & cost.ResourceCost & " " & cost.ResourceTypeName)
                        resusenode.ImageIndex = 5
                        resusenode.SelectedImageIndex = 5
                        ruleNode.Nodes.Add(resusenode)
                    Next
                End If
                tvwSecondary.Nodes.Add(ruleNode)
            Next ru
        End If



        For Each resPool As ResourcePoolItem In inst.Resources
            Dim resNode As New TreeNode
            Dim childNode As New TreeNode
            Dim infoNode As New TreeNode("Click for info")

            infoNode.ForeColor = Color.DarkBlue
            infoNode.ImageIndex = 4
            infoNode.SelectedImageIndex = 4
            infoNode.Tag = "resourceinfo"

            resNode.Text = resPool.resourceTypeptr.ResourceName & " [" & resPool.localAmount & "/" & resPool.maxAmount & "] + " & resPool.accrueAmount
            resNode.Tag = resPool
            resNode.SelectedImageIndex = 1
            resNode.ImageIndex = 1

            resNode.Nodes.Add(infoNode)
            tvwSecondary.Nodes.Add(resNode)

            'res = obj.ObjectiveResources.Item(key)
            'resNode.Text = res.ResourceName & " [" & res.CurrentAmount & "/" & res.MaxAmount & "] + " & res.AccrueAmount
            'resNode.Tag = CampaignerGameData.CDGKEY_RESOURCETYPE & res.ResourceTypeID
            'resNode.ImageIndex = 1
            'resNode.SelectedImageIndex = 1
            'childNode.Text = "Accrue Amount: " & res.AccrueAmount
            'childNode.ImageIndex = 2
            'childNode.SelectedImageIndex = 2
            'resNode.Nodes.Add(childNode)

            'Dim clickToUseNode As New TreeNode("Click to use")
            'clickToUseNode.ForeColor = Color.DarkBlue
            'clickToUseNode.ImageIndex = 4
            'clickToUseNode.SelectedImageIndex = 4
            'clickToUseNode.Tag = res.Key

            'resNode.Nodes.Add(clickToUseNode)
            'resNode.Nodes.Add(infoNode)

            'tvwSecondary.Nodes.Add(resNode)
        Next


        'For Each key In obj.ObjectiveResources.HT.Keys
        '    Dim resNode As New TreeNode
        '    Dim childNode As New TreeNode
        '    Dim infoNode As New TreeNode("Click for info")

        '    infoNode.ForeColor = Color.DarkBlue
        '    infoNode.ImageIndex = 4
        '    infoNode.SelectedImageIndex = 4
        '    infoNode.Tag = "resourceinfo"
        '    res = obj.ObjectiveResources.Item(key)
        '    resNode.Text = res.ResourceName & " [" & res.CurrentAmount & "/" & res.MaxAmount & "] + " & res.AccrueAmount
        '    resNode.Tag = CampaignerGameData.CDGKEY_RESOURCETYPE & res.ResourceTypeID
        '    resNode.ImageIndex = 1
        '    resNode.SelectedImageIndex = 1
        '    childNode.Text = "Accrue Amount: " & res.AccrueAmount
        '    childNode.ImageIndex = 2
        '    childNode.SelectedImageIndex = 2
        '    resNode.Nodes.Add(childNode)

        '    Dim clickToUseNode As New TreeNode("Click to use")
        '    clickToUseNode.ForeColor = Color.DarkBlue
        '    clickToUseNode.ImageIndex = 4
        '    clickToUseNode.SelectedImageIndex = 4
        '    clickToUseNode.Tag = res.Key

        '    resNode.Nodes.Add(clickToUseNode)
        '    resNode.Nodes.Add(infoNode)

        '    tvwSecondary.Nodes.Add(resNode)
        'Next
    End Sub

    Private Sub Populate(ByRef batt As BattlegroupChit)

        batt.calculateProperties()

        'instead of showing available orders, we're going to list rules here, just like installations. These two functions can be combined in the future.
        tvwSecondary.Nodes.Clear()
        Dim key As String
        Dim rule As Rule
        Dim ruleT As RuleType

        ' orders
        cboOrders.Text = batt.order
        cboOrders.Enabled = True

        '// statistics
        Try
            Dim statStrength As Single
            statStrength = batt.movementSpeed / FastestSpeed
            drawBar(statStrength, picSpeed, "Movement Speed")
            statStrength = batt.deployedpointvalue / HighestMaxPV
            drawBar(statStrength, picMaxPointValue, "Maximum PV")
            statStrength = batt.CurrentPV / batt.deployedpointvalue
            drawBar(statStrength, picCurrentPVPercent, "Current PV %")
        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try

        Dim rul As Rule
        For Each rul In batt.chitRules
            Dim nod As New TreeNode("[" & rul.ptrRule.RuleName & "]")
            nod.Tag = rul
            tvwSecondary.Nodes.Add(nod)
        Next

        tvwSecondary.ShowRootLines = False

        ' set up the additional information for units
        Dim newNode As New TreeNode
        newNode.Text = "Movement: " & batt.movementSpeed
        newNode.ImageIndex = 5
        newNode.SelectedImageIndex = 5
        tvwProperties.Nodes.Add(newNode)

        newNode = New TreeNode
        '// if we use override point value, show that value, if not, use suggested.
        If batt.overridePointValue > 0 Then
            newNode.Text = "Point Value: " & batt.overridePointValue & " [" & batt.deployedpointvalue & "] override"
        Else
            newNode.Text = "Point Value: " & batt.SuggestedPointValue & " [" & batt.deployedpointvalue & "]"
        End If
        newNode.ImageIndex = 6
        newNode.SelectedImageIndex = 6
        tvwProperties.Nodes.Add(newNode)

        newNode = New TreeNode
        newNode.Text = "Reinforcement Range: " & batt.effectiveReinforcement
        newNode.ImageIndex = 14
        newNode.SelectedImageIndex = 14
        tvwProperties.Nodes.Add(newNode)

        newNode = New TreeNode
        newNode.Text = "Status: " & batt.Status.ToString
        newNode.ImageIndex = 7
        newNode.SelectedImageIndex = 7
        tvwProperties.Nodes.Add(newNode)

        newNode = New TreeNode
        newNode.Text = "Waypoint Length: " & WayLength(ptrSelectedChit)
        newNode.ImageIndex = 16
        newNode.SelectedImageIndex = 16
        '// put each waypoint in here! Yah!
        For Each swayp As SmartWaypoint In batt.waypoints
            Dim wapNode As New CampaignerItemTreeNode()
            wapNode.ItemType = CampaignerItem_cgd.waypoint
            wapNode.Item = swayp
            'wapNode.Text = swayp.OrderText & " (" & swayp.Speed & " mph)"
            wapNode.Text = WaypointText(swayp)
            wapNode.SelectedImageIndex = 17
            wapNode.ImageIndex = 17
            newNode.Nodes.Add(wapNode)
        Next


        tvwProperties.Nodes.Add(newNode)

        'TASK: put in treenode of all units and battlegroups in the battlegroup
        tvwProperties.Nodes.Add(BGNode(batt))

        ' show rules in range
        'ShowRulesInRange(unit.Location)

    End Sub

    Private Function WaypointText(ByRef swap As SmartWaypoint) As String
        Dim text As String
        Try
            Return swap.OrderText & " (" & swap.Speed & " mph)"
        Catch ex As Exception
            Return "Error in text."
        End Try
    End Function


    Private Function BGNode(ByRef bg As BattlegroupChit) As TreeNode
        Try

            Dim nod As New TreeNode
            nod.Text = bg.Name
            nod.SelectedImageIndex = 12
            nod.ImageIndex = 12
            For Each mem As ChitMember In bg.members
                If mem.UnitType = GroundChitClass_cgd.Battlegroup Then
                    nod.Nodes.Add(BGNode(mem))
                Else
                    Dim unNode As New TreeNode(mem.Name)
                    unNode.ImageIndex = 13
                    unNode.SelectedImageIndex = 13
                    If mem.Status = GroundUnitStatus_cgd.Dead Then
                        unNode.ForeColor = Color.DarkRed
                        '// give it a skully
                        unNode.SelectedImageIndex = 15
                        unNode.ImageIndex = 15
                    End If
                    '// Elllllll eeeeeee ments!!!
                    If mem.UnitType = GroundChitClass_cgd.Unit Then
                        Dim un As ChitUnitTypeMember = mem
                        For Each e As ElementType In un.elements
                            Dim elenode As New TreeNode(e.ElementTypeName)
                            elenode.ImageIndex = 10
                            elenode.SelectedImageIndex = 10
                            unNode.Nodes.Add(elenode)
                        Next
                    End If
                    nod.Nodes.Add(unNode)
                End If
            Next
            Return nod

        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try
    End Function

    Public ReadOnly Property SelectedChit() As ChitMember
        Get
            Return ptrSelectedChit
        End Get
    End Property

    Private Sub PopulateBaseProperties()
        ' clear the treeview
        Dim node As New TreeNode

        tvwProperties.Nodes.Clear()

        txtSelectedChitName.Text = ptrSelectedChit.Name

        ' statistics common to installations and units
        Dim StatStrength As Single
        StatStrength = ptrSelectedChit.Size / BiggestSize
        If StatStrength > 1 Then StatStrength = 1 ' this occurs when a titanic object is on the field.
        drawBar(StatStrength, picSize, "Size")
        StatStrength = ptrSelectedChit.ZOC / BiggestZOC
        drawBar(StatStrength, picZOC, "Zone Of Control")

        With tvwProperties.Nodes
            'TASK: modify to show miles and other useful info
            node.Text = "LOS: " & ptrSelectedChit.LOS
            node.ImageIndex = 0
            node.SelectedImageIndex = 0
            .Add(node)

            node = New TreeNode
            node.Text = "LOS Power: " & ptrCurrentGame.TextForLOSPower(ptrSelectedChit.LOSPower)
            node.ImageIndex = 1
            node.SelectedImageIndex = 1
            .Add(node)

            node = New TreeNode
            node.Text = "Size : " & ptrCurrentGame.TextForSize(ptrSelectedChit.Size)
            node.ImageIndex = 2
            node.SelectedImageIndex = 2
            .Add(node)

            node = New TreeNode
            node.Text = "Terrain: " & ptrSelectedChit.CurrentTerrainName
            node.ImageIndex = 3
            node.SelectedImageIndex = 3
            .Add(node)

            node = New TreeNode
            node.Text = "ZOC: " & ptrSelectedChit.ZOC
            node.ImageIndex = 4
            node.SelectedImageIndex = 4
            .Add(node)

        End With

    End Sub

    Private Function WayLength(ByRef ch As BattlegroupChit) As String
        '// returns the waypoint length of the provided chit
        Try
            Dim text As String = "0 miles"
            Dim p As Point
            Dim x As Integer
            Dim dist As Long

            Dim obj As Object
            For Each obj In ch.waypoints
                If x = 0 Then
                    dist += XYDistance(ch.Location, ch.waypoints.item(x).LOC)
                Else
                    dist += XYDistance(ch.waypoints.item(x - 1).LOC, ch.waypoints.item(x).LOC)
                End If
                x += 1
            Next

            '// now we can total up the distance and turn it to string
            Dim mi As Single = dist / m_PixelsPerOneMile
            If dist > 0 Then text = Math.Round(mi, 2) & " miles"

            Return text

        Catch ex As Exception
            Return "N/A"
        End Try
    End Function


    Private Sub ListElements(ByRef unit As UnitType, ByRef node As TreeNode)
        Try

            Dim group As ElementGroup
            Dim EleGroup As GroupableElements = unit.ChitElements

            If unit.ChitElements.Count = 0 Then Exit Sub

            For Each group In EleGroup.Groups
                Dim GroupNode As New CampaignerItemTreeNode
                GroupNode.Text = group.GroupName
                GroupNode.ItemType = CampaignerItem_cgd.ElementGroup
                GroupNode.Item = group
                GroupNode.ImageIndex = 9
                GroupNode.SelectedImageIndex = 9
                node.Nodes.Add(GroupNode)
            Next

            Dim ele As GroupableElement
            Dim opt As ElementOption

            '// first post the Non-grouped elements
            For Each ele In EleGroup
                If ele.GroupName = "<Ungrouped>" Then
                    Dim ungroupedelenode As New CampaignerItemTreeNode

                    For Each opt In ele.Options
                        Dim optNode As New TreeNode
                        optNode.Text = opt.ElementOptionTypeName & " (" & opt.ElementOptionPointCost & ")"
                        optNode.SelectedImageIndex = 11
                        optNode.ImageIndex = 11
                        ungroupedelenode.Nodes.Add(optNode)
                    Next

                    ungroupedelenode.Text = ele.Count & "x " & ele.ElementTypeName & " (" & ele.TotalCost & ")"
                    ungroupedelenode.ImageIndex = 10
                    ungroupedelenode.SelectedImageIndex = 10
                    ungroupedelenode.ItemType = CampaignerItem_cgd.Element
                    ungroupedelenode.Item = ele
                    node.Nodes.Add(ungroupedelenode)
                End If
            Next

            '// now go through all of the elements and find the group it belongs to
            For Each ele In EleGroup
                Dim nodie As TreeNode
                For Each nodie In node.Nodes
                    If ele.GroupName = nodie.Text Then
                        Dim eleNode As New CampaignerItemTreeNode

                        For Each opt In ele.Options
                            Dim optNode As New TreeNode
                            optNode.Text = opt.ElementOptionTypeName
                            optNode.SelectedImageIndex = 11
                            optNode.ImageIndex = 11
                            eleNode.Nodes.Add(optNode)
                        Next

                        eleNode.Text = ele.Count & "x " & ele.ElementTypeName & " (" & ele.TotalCost & ")"
                        eleNode.ImageIndex = 10
                        eleNode.SelectedImageIndex = 10
                        eleNode.ItemType = CampaignerItem_cgd.Element
                        eleNode.Item = ele
                        nodie.Nodes.Add(eleNode)
                    End If
                Next
            Next
        Catch ex As Exception
            HandleException("frmChitTreeHierarchy.BuildTree", ex)
        End Try
    End Sub


    Private Sub ShowElements(ByRef unit As UnitType, ByRef node As TreeNode)
        '// adds the elements to the node

        Dim gEle As GroupableElement


    End Sub

    Private Sub ShowRulesInRange(ByVal location As Point)
        'Dim gc As GroundChitType
        'Dim gcKey As String
        'Dim obj As ObjectiveType
        'Dim ruleKey As String
        'Dim tok As TokenType
        'Dim rulet As RuleType
        'Dim rul As Rule
        'Dim bAddRule As Boolean
        'Dim modifiedRange As Integer

        'For Each gcKey In ptrCurrentGame.AllChits.Keys
        '    gc = ptrCurrentGame.AllChits.Item(gcKey)
        '    Select Case gc.GroundChitClass
        '        Case Is = GroundChitClass_cgd.Objective
        '            If ptrSelectedChit.OwningFaction = gc.OwningFaction Then
        '                obj = gc
        '                For Each rul In gc.GCRules
        '                    rulet = ptrCurrentGame.RuleTypes_g.Item(CampaignerGameData.CDGKEY_RULETYPE & rul.ruleTypeID)

        '                    bAddRule = False

        '                    modifiedRange = (rulet.BasicRange * m_PixelsPerOneMile) / 2

        '                    If XYDistance(obj.Location.X, location.X, obj.Location.Y, location.Y) <= modifiedRange Then
        '                        bAddRule = True
        '                    Else
        '                        bAddRule = False
        '                    End If

        '                    ' add this rule
        '                    If bAddRule = True Then
        '                        Dim nodString As String
        '                        Select Case rulet.AppliesDuring
        '                            Case RuleApplies_cgd.Combat : nodString = "[Combat] "
        '                            Case RuleApplies_cgd.Constant : nodString = "[Always] "
        '                            Case RuleApplies_cgd.NonCombat : nodString = "[Non-Combat] "
        '                        End Select
        '                        Dim nod As New TreeNode(nodString & rulet.RuleName)
        '                        tvwProperties.Nodes.Add(nod)
        '                    End If

        '                Next
        '            End If
        '        Case Is = GroundChitClass_cgd.Token
        '            ' TODO: handle token rule
        '    End Select
        'Next

    End Sub

    Private Sub ColorOrdersList()
        ' when viewing a unit, tvwsecondary is used to display orders, and to select an order
        'Dim unit As ChitMember = ptrSelectedChit
        'Dim key As String

        'Dim nod As TreeNode
        'For Each nod In tvwSecondary.Nodes
        '    If nod.Text = unit.Order Then
        '        nod.BackColor = Color.LightSkyBlue
        '    Else
        '        nod.BackColor = Color.White
        '    End If
        'Next
    End Sub


    Private Sub tvwSecondary_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvwSecondary.AfterSelect
        ' determine what in the world we are selecting then act accordingly
        Try
            'Select Case ptrSelectedChit.UnitType
            '    Case GroundChitClass_cgd.Objective
            ' additional rule info

            If TypeOf e.Node.Tag Is Rule Then
                RaiseEvent ShowRuleRange(e.Node.Tag)
                Exit Sub
            End If

            If e.Node.Tag = "ruleinfo" Then
                RaiseEvent ShowRuleDetails(e.Node.Parent.Tag)
                Exit Sub
            End If
            If e.Node.Text = "Click to use" Then
                RaiseEvent ResourceSelected(e.Node.Tag)
                Exit Sub
            End If
            ' additional resource info
            If e.Node.Tag = "resourceinfo" Then
                RaiseEvent ShowResourceDetails(e.Node.Parent.Tag)
                Exit Sub
            End If

            If e.Node.Tag <> "" Then
                ' determine if we selected a rule or resource
                Dim tagString As String = e.Node.Tag
                If tagString.StartsWith(CampaignerGameData.CDGKEY_RESOURCETYPE) Then
                    ' RaiseEvent ResourceSelected(e.Node.Tag)
                Else
                    RaiseEvent ShowRuleRange(e.Node.Tag)
                End If
            Else
                ' try parent
                If e.Node.Parent.Tag <> "" Then
                    Dim tagString As String = e.Node.Parent.Tag
                    If tagString.StartsWith(CampaignerGameData.CDGKEY_RESOURCETYPE) Then
                        'RaiseEvent ResourceSelected(e.Node.Parent.Tag)
                    Else
                        RaiseEvent ShowRuleRange(e.Node.Parent.Tag)
                    End If
                End If
            End If
            '    Case GroundChitClass_cgd.Battlegroup
            '        ' if the afterselect is called while clearing the list, we should ignore it.
            '        ' if we're in readonlyunit mode, ignore calls
            '        If unitReadOnly = True Then Exit Sub
            '        If Not populatingOrdersList Then SetUnitOrder(e.Node.Text.ToString)
            'End Select
        Catch ex As Exception

        End Try

    End Sub

    Private Sub SetUnitOrder(ByVal newOrder As String)
        If ptrSelectedChit.UnitType <> GroundChitClass_cgd.Battlegroup Then Exit Sub
        Dim unit As BattlegroupChit = DirectCast(ptrSelectedChit, BattlegroupChit)

        unit.order = newOrder
        Debug.WriteLine(unit.ToString & " has orders " & unit.order)
        ColorOrdersList()

    End Sub

    Private Sub cboOrders_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboOrders.SelectedIndexChanged
        If ptrSelectedChit Is Nothing Then Exit Sub

        If ptrSelectedChit.UnitType = GroundChitClass_cgd.Battlegroup Then
            DirectCast(ptrSelectedChit, BattlegroupChit).order = cboOrders.Text
        End If

    End Sub

    Private Sub tvwProperties_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles tvwProperties.MouseUp

        If e.Button <> Windows.Forms.MouseButtons.Right Then Exit Sub

        If TypeOf Me.tvwProperties.SelectedNode Is CampaignerItemTreeNode Then

            If DirectCast(tvwProperties.SelectedNode, CampaignerItemTreeNode).ItemType = CampaignerItem_cgd.waypoint Then
                mnuWaypointPopup.Show(sender, e.X, e.Y)
                '// if we delete the waypoint, there is nothing
                If Not tvwProperties.SelectedNode Is Nothing Then

                End If
            Else
                MessageBox.Show(DirectCast(tvwProperties.SelectedNode, CampaignerItemTreeNode).ItemType, "whooo", MessageBoxButtons.OK)
            End If


        End If

    End Sub

    Private Sub mnuHold_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuHold.Click
        Try
            Dim swap As SmartWaypoint = DirectCast(tvwProperties.SelectedNode, CampaignerItemTreeNode).Item
            swap.OrderText = "Hold"
            tvwProperties.SelectedNode.Text = WaypointText(DirectCast(tvwProperties.SelectedNode, CampaignerItemTreeNode).Item)
        Catch ex As Exception
            HandleException("ctlSelectedChitProperties.menuclick", ex)
        End Try
    End Sub

    Private Sub mnuDigin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuDigin.Click
        Try
            Dim swap As SmartWaypoint = DirectCast(tvwProperties.SelectedNode, CampaignerItemTreeNode).Item
            swap.OrderText = "Dig-in"

            tvwProperties.SelectedNode.Text = WaypointText(DirectCast(tvwProperties.SelectedNode, CampaignerItemTreeNode).Item)
        Catch ex As Exception
            HandleException("ctlSelectedChitProperties.menuclick", ex)
        End Try
    End Sub

    Private Sub mnuEngage_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuEngage.Click
        Try
            Dim swap As SmartWaypoint = DirectCast(tvwProperties.SelectedNode, CampaignerItemTreeNode).Item
            swap.OrderText = "Engage"
            tvwProperties.SelectedNode.Text = WaypointText(DirectCast(tvwProperties.SelectedNode, CampaignerItemTreeNode).Item)
        Catch ex As Exception
            HandleException("ctlSelectedChitProperties.menuclick", ex)
        End Try
    End Sub

    Private Sub mnuWithdraw_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuWithdraw.Click
        Try
            Dim swap As SmartWaypoint = DirectCast(tvwProperties.SelectedNode, CampaignerItemTreeNode).Item
            swap.OrderText = "Withdraw"
            tvwProperties.SelectedNode.Text = WaypointText(DirectCast(tvwProperties.SelectedNode, CampaignerItemTreeNode).Item)
        Catch ex As Exception
            HandleException("ctlSelectedChitProperties.menuclick", ex)
        End Try
    End Sub

    Private Sub mnu100speed_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnu100speed.Click
        Try
            Dim citn As CampaignerItemTreeNode = DirectCast(tvwProperties.SelectedNode, CampaignerItemTreeNode)
            Dim bg As BattlegroupChit = ptrSelectedChit
            Dim speed As Single = bg.movementSpeed

            'speed = DirectCast(citn.Item, SmartWaypoint).Speed
            DirectCast(citn.Item, SmartWaypoint).Speed = speed
            tvwProperties.SelectedNode.Text = WaypointText(DirectCast(tvwProperties.SelectedNode, CampaignerItemTreeNode).Item)


        Catch ex As Exception
            HandleException("ctlSelectedChitProperties.Speedmenuclick", ex)
        End Try
    End Sub

    Private Sub mnu25speed_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnu25speed.Click
        Try
            Dim citn As CampaignerItemTreeNode = DirectCast(tvwProperties.SelectedNode, CampaignerItemTreeNode)
            Dim bg As BattlegroupChit = ptrSelectedChit
            Dim speed As Single = bg.movementSpeed * 0.25

            'speed = DirectCast(citn.Item, SmartWaypoint).Speed * 0.25
            DirectCast(citn.Item, SmartWaypoint).Speed = speed
            tvwProperties.SelectedNode.Text = WaypointText(DirectCast(tvwProperties.SelectedNode, CampaignerItemTreeNode).Item)


        Catch ex As Exception
            HandleException("ctlSelectedChitProperties.Speedmenuclick", ex)
        End Try
    End Sub

    Private Sub mnu50speed_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnu50speed.Click
        Try
            Dim citn As CampaignerItemTreeNode = DirectCast(tvwProperties.SelectedNode, CampaignerItemTreeNode)
            Dim bg As BattlegroupChit = ptrSelectedChit
            Dim speed As Single = bg.movementSpeed * 0.5

            ' speed = DirectCast(citn.Item, SmartWaypoint).Speed * 0.5
            DirectCast(citn.Item, SmartWaypoint).Speed = speed
            tvwProperties.SelectedNode.Text = WaypointText(DirectCast(tvwProperties.SelectedNode, CampaignerItemTreeNode).Item)


        Catch ex As Exception
            HandleException("ctlSelectedChitProperties.Speedmenuclick", ex)
        End Try
    End Sub

    Private Sub mnu75speed_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnu75speed.Click
        Try
            Dim citn As CampaignerItemTreeNode = DirectCast(tvwProperties.SelectedNode, CampaignerItemTreeNode)
            Dim bg As BattlegroupChit = ptrSelectedChit
            Dim speed As Single = bg.movementSpeed * 0.75

            'speed = DirectCast(citn.Item, SmartWaypoint).Speed * 0.75
            DirectCast(citn.Item, SmartWaypoint).Speed = speed
            tvwProperties.SelectedNode.Text = WaypointText(DirectCast(tvwProperties.SelectedNode, CampaignerItemTreeNode).Item)


        Catch ex As Exception
            HandleException("ctlSelectedChitProperties.Speedmenuclick", ex)
        End Try
    End Sub

    Private Sub mnuEnterspeed_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuEnterspeed.Click
        Try

            Dim citn As CampaignerItemTreeNode = DirectCast(tvwProperties.SelectedNode, CampaignerItemTreeNode)
            Dim bg As BattlegroupChit = ptrSelectedChit
            Dim speed As Single = bg.movementSpeed


            Dim fenter As New frmBasicEntry("Enter new speed for this Battlegroup.", "[0-9]*")
            fenter.ShowDialog()
            If IsNumeric(fenter.Data) Then
                speed = CSng(fenter.Data)

                If speed > bg.movementSpeed Then
                    '// yell
                    MessageBox.Show("You must select a speed less than or equal to the maximum speed of the Battlegroup.", "Enter Speed", MessageBoxButtons.OK)

                Else
                    DirectCast(citn.Item, SmartWaypoint).Speed = speed

                    tvwProperties.SelectedNode.Text = WaypointText(DirectCast(tvwProperties.SelectedNode, CampaignerItemTreeNode).Item)

                End If

            Else
                MessageBox.Show("Please enter a valid speed between 0 and the maximum speed of the battlegroup", "Enter Speed", MessageBoxButtons.OK)

            End If


        Catch ex As Exception
            HandleException("ctlSelectedChitProperties.Speedmenuclick", ex)
        End Try
    End Sub

    Private Sub mnuRemoveWaypoint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuRemoveWaypoint.Click
        Try
            Dim citn As CampaignerItemTreeNode = DirectCast(tvwProperties.SelectedNode, CampaignerItemTreeNode)

            Dim bg As BattlegroupChit = ptrSelectedChit
            bg.waypoints.remove(citn.Item)
            tvwProperties.Nodes.Remove(tvwProperties.SelectedNode)

            '// call for a redraw
            RaiseEvent RedrawRequest()

        Catch ex As Exception
            HandleException("mnuRemoveWaypoint", ex)
        End Try
    End Sub

    Private Sub mnuRemoveAllWaypoints_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuRemoveAllWaypoints.Click
        Try

            Dim bg As BattlegroupChit = ptrSelectedChit
            bg.waypoints.Clear()
            tvwProperties.SelectedNode.Parent.Nodes.Clear()
            ShowSelectedChitProperties(bg, ptrCurrentGame)

            '// call for a redraw
            RaiseEvent RedrawRequest()

        Catch ex As Exception
            HandleException("ctlSelectedChitProperties.menuclick", ex)
        End Try
    End Sub
End Class

